#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e4 + 10, INF = 0x3f3f3f3f;

ll n, k, m, q;
ll a[N];

ll ksm(ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % n;
        a = a * a % n;b >>= 1;
    }
    return res;
}

void solve()
{
    cin >> n >> k >> m >> q;
    for (ll i = 1;i <= m;i++) {
        ll x; cin >> x;
        for (ll i = 1;i <= k;i++) a[ksm(x, i) % n] = 1;
    }
    for (ll i = 1;i <= q;i++) {
        ll y, flag = 1;cin >> y;
        for (ll i = 1;i <= k;i++)
            if (a[ksm(y, i) % n] == 0) {
                flag = 0;
                cout << 0 << ' ';
                break;
            }
        if (flag) cout << 1 << ' ';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}